package com.ssy.lingxi.member.merchant.controller.feign;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.MemberSalesCountFeignVO;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.MemberSalesFindMemberVO;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.MemberSalesFindUserIdVO;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.response.*;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.ChannelListVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberSalesChannelFindUserIdQueryVO;
import com.ssy.lingxi.member.merchant.service.feign.IMemberAbilitySalesFeignService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 业务员相关内部Feign接口
 *
 * @author 郑小翠
 * @version 2.02.18
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/member/feign/ability/sales")
public class MemberAbilitySalesFeignController {

    @Resource
    private IMemberAbilitySalesFeignService memberAbilitySalesService;

    /**
     * 业绩统计
     *
     * @param pageVO 接口参数
     * @return 返回符合条件的业务员列表和下级会员
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Wrapper<PageData<MemberFeignSalesCountVO>> memberSalesList(@RequestBody @Valid MemberSalesCountFeignVO pageVO) {
        return memberAbilitySalesService.getMemberSalesList(pageVO);
    }

    /**
     * 获取角色类型为消费者的角色Id
     *
     * @return 返回角色类型为消费者的角色Id
     */
    @RequestMapping(value = "/roleIds", method = RequestMethod.GET)
    public Wrapper<List<Long>> roleIds() {
        return memberAbilitySalesService.getRoleIds();
    }

    /**
     * 根据业务员Id查询下级会员信息
     *
     * @param pageVO 查询条件
     * @return 返回下级会员信息
     */
    @RequestMapping(value = "/findByUserId", method = RequestMethod.POST)
    public Wrapper<PageData<MemberSalesFeignPageQueryVO>> findByUserId(@RequestBody @Valid MemberSalesFindUserIdVO pageVO) {
        return memberAbilitySalesService.findByUserId(pageVO);
    }

    /**
     * 根据当前账号以及搜索条件查找下级渠道会员
     *
     * @param pageVO 查询条件
     * @return 返回业务员和下级会员信息
     */
    @RequestMapping(value = "/findMemberSales", method = RequestMethod.POST)
    public Wrapper<List<MemberSalesFindMemberQueryVO>> findMemberSales(@RequestBody @Valid MemberSalesFindMemberVO pageVO) {
        return memberAbilitySalesService.findMemberSales(pageVO);
    }

    /**
     * 订单能力-业务员业绩详情-查看业务员详情
     *
     * @param headers 头部信息
     * @param userId  业务员Id
     * @return 返回业务员信息
     */
    @RequestMapping(value = "/channel/information", method = RequestMethod.GET)
    public Wrapper<MemberSalesChannelFindUserIdQueryVO> getChannelInformation(@RequestHeader HttpHeaders headers, @NotNull Long userId) {
        return memberAbilitySalesService.getChannelInformation(headers, userId);
    }

    /**
     * 根据数据权限找出符合条件的业务员信息Id
     *
     * @param pageVO 头部信息
     * @return 返回业务员Id和名字
     */
    @RequestMapping(value = "/userIds", method = RequestMethod.POST)
    public Wrapper<List<MemberUserVO>> getUserIds(@RequestBody @Valid MemberSalesCountFeignVO pageVO) {
        return memberAbilitySalesService.getUserIds(pageVO);
    }
}
